package com.ponhu.ea2.goodsCenter.provider.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ponhu.ea2.entity.GoodsDataCreateorupdateLog;
import com.ponhu.ea2.goodsCenter.provider.mapper.GoodsDataCreateorupdateLogMapper;
import com.ponhu.ea2.goodsCenter.provider.service.GoodsDataCreateorupdateLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * <p>
 *  对接胖总管,wms,库存中心日志记录
 * </p>
 *
 * @author ${author}
 * @since 2021-10-26
 */
@Slf4j
@Service
public class GoodsDataCreateorupdateLogServiceImpl extends ServiceImpl<GoodsDataCreateorupdateLogMapper, GoodsDataCreateorupdateLog> implements GoodsDataCreateorupdateLogService {

    @Resource
    private GoodsDataCreateorupdateLogMapper goodsDataCreateorupdateLogMapper;

    /**
     * 保存错误日志
     * @param type
     * @param msg
     * @param inventoryId
     */
    @Override
    public void saveLog(String type, String msg, String inventoryCode,String sourceData){
        GoodsDataCreateorupdateLog goodsDataCreateorupdateLog = new GoodsDataCreateorupdateLog();
        goodsDataCreateorupdateLog.setCreateTime(LocalDateTime.now());
        goodsDataCreateorupdateLog.setErrorMsg(msg);
        goodsDataCreateorupdateLog.setType(type);
        goodsDataCreateorupdateLog.setInventoryCode(inventoryCode);
        goodsDataCreateorupdateLog.setErrorStatus("0");
        goodsDataCreateorupdateLog.setSourceData(sourceData);
        goodsDataCreateorupdateLogMapper.insert(goodsDataCreateorupdateLog);
    }

    @Override
    public GoodsDataCreateorupdateLog getLog(String inventoryCode, String type) {
        return goodsDataCreateorupdateLogMapper
                .selectOne(new LambdaQueryWrapper<GoodsDataCreateorupdateLog>()
                        .eq(GoodsDataCreateorupdateLog::getErrorStatus, "0")
                        .eq(GoodsDataCreateorupdateLog::getInventoryCode,inventoryCode)
                        .eq(GoodsDataCreateorupdateLog::getType, type));
    }
}
